Skip to content

gen~ data from WAV resources - #136

Open
pingdynasty wants to merge 7 commits into
masterfrom
feature/gen-resources
Open

pingdynasty wants to merge 7 commits into
masterfrom
feature/gen-resources

Conversation

@pingdynasty

Copy link
Copy Markdown
Collaborator

Loads WAV resources into gen~ data: a data object named after a resource is filled from the WAV file. Based on #115 (its two commits are kept as they are), with fixes and tests on top.

From #115

  • genlib_obtain_reference_from_string() loads the named resource; genlib_obtain_data_from_reference() fills the data object from a valid WAV file
  • WavFile::read(channel, output, all) and WavFile::createFloatArray() for interleaved reads

Fixes on top

  • WavFile::read(all=true) read one channel's worth of samples, so stereo files filled only half the buffer
  • The buffer is allocated with sysmem_newptr(), matching the sysmem_freeptr() in genlib_data_release() (it was new[] from FloatArray::create())
  • Loading resources in gen~ #115 stopped genlib_data_resize() zeroing every data object; now only data loaded from a resource is kept, and plain gen~ data is cleared on reset as before
  • A declared size that differs from the WAV file is reported with debugMessage() (data frames / WAV frames 6 4, data channels / WAV channels 1 2); overlapping frames and channels are kept, the rest is zeroed
  • WavFile decoded 8-bit PCM as signed; WAV stores 8-bit samples unsigned (128 = 0)
  • make tests starts from a clean build directory: generated Gen/Faust/Heavy sources left in Build/Source were linked into every unit test

Tests

  • WavFileTest: header, per-channel and interleaved reads, 16-bit stereo, 8-bit unsigned, mono float
  • GenDataResourceTest: gen~ Data::reset() through the native resource loader (reads files), stereo loaded exactly and kept across reset, declared longer, declared mono, size messages, plain data zeroed on reset. Fails on the Loading resources in gen~ #115 code as-is.

Verification

  • make check passes (all unit tests; ARM, web + webtest and native for each test patch), also on a dirty build directory
  • OWL3 Gen patch builds without warnings
  • Not tested: a real gen~ export loading a WAV resource on a device

Note: every gen~ data and delay line looks up a resource with its own name at startup, so a resource that happens to share a data object's name is loaded into it.

antisvin and others added 7 commits November 28, 2026 04:07
…mples

With all=true the loop ran getNumberOfSamples() (frames) times, so createFloatArray() filled only the first 1/channels of the interleaved buffer for multichannel files.
- Copy all channels: allocate the interleaved buffer with sysmem_newptr(), which genlib_data_release() frees with sysmem_freeptr(), instead of FloatArray::create() (new[]).
- Zero on resize again, except for data loaded from a resource; plain gen~ data is cleared on reset as before.
- Report a declared size that differs from the WAV file with debugMessage(): the overlapping frames and channels are kept.
WavFileTest: header, per-channel and interleaved reads. GenDataResourceTest: gen~ Data::reset() filled from a WAV file through the native resource loader, declared size longer and mono, size-mismatch messages, plain data zeroed on reset.
WAV stores 8-bit samples as unsigned with 128 as zero; they were read as int8_t, so 128 became -1.0 and the waveform was inverted and offset. Test added to WavFileTest.
Native tests compile every source in Build/Source, so generated Gen/Faust/Heavy sources left by an earlier patch build were linked into each unit test (duplicate symbols with GenDataResourceTest, which includes genlib.cpp).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants